﻿using System;
using PostSharp.Laos;
using TestBat.IModels.Exceptions;
using TestBat.IViewModels.Dialogs;
using TestBat.ServiceLocator;
using TestBat.ViewModels.Dialogs;

namespace TestBat.ViewModels.Attributes
{
    [Serializable]
    public class ValidationErrorDialogAttribute : OnMethodBoundaryAspect 
    {
        public override void OnException(MethodExecutionEventArgs eventArgs)
        {
            if (eventArgs.Exception is IValidationException)
            {
                IValidationException e = eventArgs.Exception as IValidationException;
                DefaultServiceLocator.Get<IDialogMediator>().DialogViewModel = new ValidationErrorDialogViewModel(e);
                eventArgs.FlowBehavior = FlowBehavior.Continue;
            }
        }
    }
}
